#ifndef T_BOX_H
#define T_BOX_H

#include "stable.h"

#define USE_DECODE_THREAD 0
//#define USE_DECODE_THREAD 1

class T_Box
{
public:
    enum
    {
        PLAYER_HEAD_HEADGE = 2000,
        PLAYER_BUFFER_TIME = 6000,
        PLAYER_AHEAD_IMAGE = 5, PLAYER_ENOUGH_IMAGE = 10, PLAYER_IMAGE_STOCK = 20,
        //PLAYER_AHEAD_IMAGE = 1, PLAYER_ENOUGH_IMAGE = 1, PLAYER_IMAGE_STOCK = 2,
        //PLAYER_AHEAD_IMAGE = 15,
        //PLAYER_IMAGE_STOCK = 60,
        //PLAYER_IMAGE_STOCK = 120,
        //PLAYER_IMAGE_STOCK = 240,
    };
    explicit T_Box();
};



#if 0x0
#define BOX_DECLARE_PRIVATE(Class) \
class Class##Private *d_ptr; \
    Q_DECLARE_PRIVATE(Class)

#define BOX_DECLARE_PUBLIC(Class) \
    class Class *q_ptr; \
    Q_DECLARE_PUBLIC(Class)

#define BOX_INIT_QPTR(X) QObject(X), q_ptr(X)
#endif



class T_Box_Thread : public QThread
{
public:
    explicit T_Box_Thread()
    {
        closing(false);
    }
    void finish()
    {
        closing(true);
        this->p_wait_closing();
    }
    bool closing()
    {
        return m_closing;
    }
protected:
    void closing(bool b)
    {
        m_closing = b;
    }
    void p_wait_closing()
    {
        if(qApp->thread() != QThread::currentThread())
        {
            this->wait();
            return;
        }
        while(this->isRunning())
        {
            qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
            //msleep(1);
        }
    }
private:
    bool m_closing;
};

#endif // T_BOX_H
